﻿using LeederGlobal;
using PartsRetrospect.Business;
using PartsRetrospect.Comm;
using PartsRetrospect.Model;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PartsRetrospect.Forms
{
    public partial class FrmSetup : UIPage
    {
        bool isLoad = true;      //判断窗体是否首次加载

        SerialPortBLL erialPortBLL = new SerialPortBLL();
        IOCarEventBLL iOCarEventBLL = new IOCarEventBLL();
        BarCodeConfiBLL barCodeConfiBLL = new BarCodeConfiBLL();
        CarModelBLL carModelBLL = new CarModelBLL();
        AirbagPositionBLL airbagPositionBLL = new AirbagPositionBLL();
        AirbagConfiBLL airbagConfiBLL = new AirbagConfiBLL();
        UploadSetBLL uploadSetBLL = new UploadSetBLL();
        WorkShopSetBLL workShopSetBLL = new WorkShopSetBLL();
        AirbagOneToMoreBLL airbagOneToMoreBLL = new AirbagOneToMoreBLL();

        List<CarModelModel> carModelList;
        List<AirbagPositionModel> airbagPositionList;
        List<AirbagConfiModel> airbagConfiList;

        /// <summary>
        /// 判断新增还是修改；0新增，1修改
        /// </summary>
        int btnFlag = 0;

        UploadSetModel uploadSet;
        //WorkShopSetModel workShopSet;

        public FrmSetup()
        {
            InitializeComponent();

            //dgvSerialPort.AutoGenerateColumns = false;
            //dgvSerialPort.ReadOnly = true;

            //dgvIOCard.AutoGenerateColumns = false;
            //dgvIOCard.ReadOnly = true;

            dgvBarCode.AutoGenerateColumns = false;
            dgvBarCode.ReadOnly = true;

            dgvCarModel.AutoGenerateColumns = false;
            dgvCarModel.ReadOnly = true;

            dgvAirbagPosition.AutoGenerateColumns = false;
            dgvAirbagPosition.ReadOnly = true;

            dgvAirbagConfi.AutoGenerateColumns = false;
            dgvAirbagConfi.ReadOnly = true;

            dgvOneToMore.AutoGenerateColumns = false;
            dgvOneToMore.ReadOnly = true;
        }

        private void FrmSetup_Load(object sender, EventArgs e)
        {
            //如果窗体已经加载过则不重新加载
            if (!isLoad)
                return;
            isLoad = false;
            carModelList = carModelBLL.GetModelAll();
            airbagPositionList = airbagPositionBLL.GetModelAll();
            airbagConfiList = airbagConfiBLL.GetModelAll();
            LoadDgv();
            uploadSet = uploadSetBLL.GetModel();
            txtStation.Text = GolbalVariable.WorkShopSet.Position;
            txtWorkshopNo.Text = GolbalVariable.WorkShopSet.WorkShopNo.ToString();
            txtComputerNo.Text = GolbalVariable.WorkShopSet.ComputerNo;
            txtScanCount.Text = GolbalVariable.WorkShopSet.ScanCount.ToString();
            txtIP.Text = uploadSet.IP;
            txtPort.Text = uploadSet.Port.ToString();
            txtUser.Text = uploadSet.UserName;
            txtPwd.Text = uploadSet.Password;
            txtUploadPath.Text = uploadSet.UploadPath;

            btnBarNew.Enabled = false;
            btnBarDelete.Enabled = false;
            btnBarSave.Enabled = false;
            btnBarCancel.Enabled = false;

            btnCarModelSave.Enabled = false;
            btnCarModelCancel.Enabled = false;

            btnPositionSave.Enabled = false;
            btnPositionCancel.Enabled = false;

            btnAirbagCofigSave.Enabled = false;
            btnAirbagCofigCancel.Enabled = false;

            btnOneToMoreSave.Enabled = false;
            btnOneToMoreCancel.Enabled = false;

            txtBarName.Enabled = false;
            txtBarValue.Enabled = false;

            txtCarModelCode.Enabled = false;
            txtCarModelEnglisName.Enabled = false;
            txtCarModelName.Enabled = false;

            txtPositionName.Enabled = false;

            txtAirbagCofig.Enabled = false;
            cbAirbagCofigCMCode.Enabled = false;
            txtAirbagFlag.Enabled = false;
            txtAirbagLength.Enabled = false;
            cbAirbagPosition.Enabled = false;

            cbOneToMoreCarModel.Enabled = false;
            cbOneToMoreVType.Enabled = false;
            cbOneToMoreAirbagGuan.Enabled = false;
            cbOneToMoreAirbag1.Enabled = false;
            cbOneToMoreAirbag2.Enabled = false;
            cbOneToMoreAirbag3.Enabled = false;
            cbOneToMoreAirbag4.Enabled = false;

            cbAirbagCofigCMCode.DataSource = carModelList;
            cbAirbagCofigCMCode.DisplayMember = "BarCodeTag";
            cbAirbagCofigCMCode.ValueMember = "BarCodeTag";
            cbAirbagPosition.DataSource = airbagPositionList;
            cbAirbagPosition.DisplayMember = "AiebagPosition";
            cbAirbagPosition.ValueMember = "AiebagPosition";

            cbOneToMoreCarModel.DataSource = airbagConfiList;
            cbOneToMoreCarModel.DisplayMember = "CarModelCode";
            cbOneToMoreCarModel.ValueMember = "CarModelCode";
            cbOneToMoreVType.DataSource = airbagConfiList;
            cbOneToMoreVType.DisplayMember = "VType";
            cbOneToMoreVType.ValueMember = "VType";

            cbOneToMoreCarModel.SelectedIndex = -1;
            //cbOneToMoreCarModel.SelectedValue = null;
            cbOneToMoreVType.SelectedIndex = -1;
            //cbOneToMoreVType.SelectedValue = null;
        }

        private void LoadDgv()
        {
            //dgvSerialPort.DataSource = null;
            //dgvIOCard.DataSource = null;
            dgvBarCode.DataSource = null;
            dgvCarModel.DataSource = null;
            dgvAirbagPosition.DataSource = null;
            dgvAirbagConfi.DataSource = null;
            //dgvSerialPort.DataSource = erialPortBLL.GetModelAll();
            //dgvIOCard.DataSource = iOCarEventBLL.GetModelAll();
            dgvBarCode.DataSource = barCodeConfiBLL.GetModelAll();
            dgvCarModel.DataSource = carModelBLL.GetModelAll();
            dgvAirbagPosition.DataSource = airbagPositionBLL.GetModelAll();
            dgvAirbagConfi.DataSource = airbagConfiBLL.GetModelAll();
            dgvOneToMore.DataSource = airbagOneToMoreBLL.GetModelAll();
        }

        UIDataGridView dataGridView;
        private void dataGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (e.RowIndex >= 0)
                {
                    dataGridView = (UIDataGridView)sender;
                    //若行已是选中状态就不再进行设置
                    if (dataGridView.Rows[e.RowIndex].Selected == false)
                    {
                        dataGridView.ClearSelection();
                        dataGridView.Rows[e.RowIndex].Selected = true;
                    }
                    //只选中一行时设置活动单元格
                    if (dataGridView.SelectedRows.Count == 1)
                    {
                        dataGridView.CurrentCell = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex];
                    }
                    //弹出操作菜单
                    uiContextMenuStrip1.Show(MousePosition.X, MousePosition.Y);
                }
            }
        }

        private void UpdateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission != 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }

            string name = dataGridView.Name;
            switch (name)
            {
                case "dgvSerialPort":
                    var serialPort = dataGridView.CurrentRow.DataBoundItem as SerialPortModel;
                    EditSerialPort(serialPort);
                    break;
                case "dgvIOCard":
                    var iOCard = dataGridView.CurrentRow.DataBoundItem as IOCarEventModel;
                    EditIOCard(iOCard);
                    break;
                case "dgvBarCode":
                    var barCode = dataGridView.CurrentRow.DataBoundItem as BarCodeConfiModel;
                    EditBarCode(barCode);
                    break;
                case "dgvCarModel":
                    var carModel = dataGridView.CurrentRow.DataBoundItem as CarModelModel;
                    EditCarModel(carModel);
                    break;
                case "dgvAirbagPosition":
                    var airbagPosition = dataGridView.CurrentRow.DataBoundItem as AirbagPositionModel;
                    EditAirbagPosition(airbagPosition);
                    break;
                case "dgvAirbagConfi":
                    var airbagConfi = dataGridView.CurrentRow.DataBoundItem as AirbagConfiModel;
                    EditAirbagConfi(airbagConfi);
                    break;
            }
            LoadDgv();
        }

        private void AddToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission != 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }
            string name = dataGridView.Name;
            switch (name)
            {
                case "dgvSerialPort":
                    EditSerialPort(new SerialPortModel());
                    break;
                case "dgvIOCard":
                    EditIOCard(new IOCarEventModel());
                    break;
                case "dgvBarCode":
                    EditBarCode(new BarCodeConfiModel());
                    break;
                case "dgvCarModel":
                    EditCarModel(new CarModelModel());
                    break;
                case "dgvAirbagPosition":
                    EditAirbagPosition(new AirbagPositionModel());
                    break;
                case "dgvAirbagConfi":
                    EditAirbagConfi(new AirbagConfiModel());
                    break;
            }
            LoadDgv();
        }

        private void DeleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission != 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }
            if (!UIMessageDialog.ShowMessageDialog("您确定要删除该设置吗？", UILocalize.AskTitle, true, UIStyle.Red, true, Frame?.TopMost ?? false))
            {
                return;
            }
            string name = dataGridView.Name;
            switch (name)
            {
                case "dgvSerialPort":
                    var serialPort = dataGridView.CurrentRow.DataBoundItem as SerialPortModel;
                    if (erialPortBLL.Delete(serialPort).IsSuccess)
                        UIMessageTip.ShowOk("删除成功");
                    else
                        UIMessageTip.ShowError("删除失败");
                    break;
                case "dgvIOCard":
                    var iOCard = dataGridView.CurrentRow.DataBoundItem as IOCarEventModel;
                    if (iOCarEventBLL.Delete(iOCard).IsSuccess)
                        UIMessageTip.ShowOk("删除成功");
                    else
                        UIMessageTip.ShowError("删除失败");
                    break;
                case "dgvBarCode":
                    var barCode = dataGridView.CurrentRow.DataBoundItem as BarCodeConfiModel;
                    if (barCodeConfiBLL.Delete(barCode).IsSuccess)
                        UIMessageTip.ShowOk("删除成功");
                    else
                        UIMessageTip.ShowError("删除失败");
                    break;
                case "dgvCarModel":
                    var carModel = dataGridView.CurrentRow.DataBoundItem as CarModelModel;
                    carModelBLL.Delete(carModel);
                    break;
                case "dgvAirbagPosition":
                    var airbagPosition = dataGridView.CurrentRow.DataBoundItem as AirbagPositionModel;
                    if (airbagPositionBLL.Delete(airbagPosition).IsSuccess)
                        UIMessageTip.ShowOk("删除成功");
                    else
                        UIMessageTip.ShowError("删除失败");
                    break;
                case "dgvAirbagConfi":
                    var airbagConfi = dataGridView.CurrentRow.DataBoundItem as AirbagConfiModel;
                    if (airbagConfiBLL.Delete(airbagConfi).IsSuccess)
                        UIMessageTip.ShowOk("删除成功");
                    else
                        UIMessageTip.ShowError("删除失败");
                    break;
            }
            LoadDgv();
        }

        private void EditSerialPort(SerialPortModel model)
        {
            string[] coms = new string[10] { "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "COM10" };
            UIEditOption option = new UIEditOption();
            option.AutoLabelWidth = true;
            option.Text = "串口设置";
            option.AddText("PortName", "串口名称", model.PortName, true);
            if (model.ID != 0)
                option.AddCombobox("PortNo", "串口号", coms, "PortNo", "PortNo", model.PortNo);
            else
                option.AddCombobox("PortNo", "串口号", coms);
            UIEditForm frm = new UIEditForm(option);
            frm.ShowDialog();
            if (frm.IsOK)
            {
                model.PortName = frm["PortName"].ToString();
                if (model.ID != 0)
                    model.PortNo = frm["PortNo"].ToString();
                else
                    model.PortNo = coms[int.Parse(frm["PortNo"].ToString())];

                model.IsPhantom = false;

                if (model.ID == 0)
                {
                    if (erialPortBLL.Add(model).IsSuccess)
                        UIMessageTip.ShowOk("新增成功");
                    else
                        UIMessageTip.ShowError("新增失败");
                }
                else
                {
                    if (erialPortBLL.Update(model).IsSuccess)
                        UIMessageTip.ShowOk("修改成功");
                    else
                        UIMessageTip.ShowError("修改失败");
                }
            }
            frm.Dispose();
        }

        private void EditIOCard(IOCarEventModel model)
        {
            UIEditOption option = new UIEditOption();
            option.AutoLabelWidth = true;
            option.Text = "IO卡设置";
            option.AddText("EventName", "事件名称", model.EventName, true);
            option.AddText("InputPoint", "输出端口", model.InputPoint, true);
            option.AddText("OutputOrder", "输出指令", model.OutputOrder, true);
            option.AddInteger("DelayTime", "延时时间", model.DelayTime, true);
            UIEditForm frm = new UIEditForm(option);
            frm.ShowDialog();
            if (frm.IsOK)
            {
                model.EventName = frm["EventName"].ToString();
                model.InputPoint = frm["InputPoint"].ToString();
                model.OutputOrder = frm["OutputOrder"].ToString();
                model.DelayTime = int.Parse(frm["DelayTime"].ToString());
                model.IsPhantom = false;

                if (model.ID == 0)
                {
                    if (iOCarEventBLL.Add(model).IsSuccess)
                        UIMessageTip.ShowOk("新增成功");
                    else
                        UIMessageTip.ShowError("新增失败");
                }
                else
                {
                    if (iOCarEventBLL.Update(model).IsSuccess)
                        UIMessageTip.ShowOk("修改成功");
                    else
                        UIMessageTip.ShowError("修改失败");
                }
            }
            frm.Dispose();
        }

        private void EditBarCode(BarCodeConfiModel model)
        {
            UIEditOption option = new UIEditOption();
            option.AutoLabelWidth = true;
            option.Text = "条码设置";
            option.AddText("Name", "条码名称", model.Name, true);
            option.AddInteger("Value1", "值", model.Value1, true);
            UIEditForm frm = new UIEditForm(option);
            frm.ShowDialog();
            if (frm.IsOK)
            {
                model.Name = frm["Name"].ToString();
                model.Value1 = int.Parse(frm["Value1"].ToString());
                model.IsPhantom = false;

                if (model.ID == 0)
                {
                    if (barCodeConfiBLL.Add(model).IsSuccess)
                        UIMessageTip.ShowOk("新增成功");
                    else
                        UIMessageTip.ShowError("新增失败");
                }
                else
                {
                    if (barCodeConfiBLL.Update(model).IsSuccess)
                        UIMessageTip.ShowOk("修改成功");
                    else
                        UIMessageTip.ShowError("修改失败");
                }
            }
            frm.Dispose();
        }

        private void EditCarModel(CarModelModel model)
        {
            UIEditOption option = new UIEditOption();
            option.AutoLabelWidth = true;
            option.Text = "车型设置";
            option.AddText("CarModelName", "车型中文名", model.CarModelName, true);
            option.AddText("CarModelCode", "车型英文名", model.CarModelCode, true);
            option.AddText("BarCodeTag", "车型条码标识", model.BarCodeTag, true);
            UIEditForm frm = new UIEditForm(option);
            frm.ShowDialog();
            if (frm.IsOK)
            {
                model.CarModelName = frm["CarModelName"].ToString();
                model.CarModelCode = frm["CarModelCode"].ToString();
                model.BarCodeTag = frm["BarCodeTag"].ToString();
                model.IsPhantom = false;

                if (model.ID == 0)
                {
                    if (carModelBLL.Add(model).IsSuccess)
                        UIMessageTip.ShowOk("新增成功");
                    else
                        UIMessageTip.ShowError("新增失败");
                }
                else
                {
                    if (carModelBLL.Update(model).IsSuccess)
                        UIMessageTip.ShowOk("修改成功");
                    else
                        UIMessageTip.ShowError("修改失败");
                }
            }
            frm.Dispose();
        }

        private void EditAirbagPosition(AirbagPositionModel model)
        {
            UIEditOption option = new UIEditOption();
            option.AutoLabelWidth = true;
            option.Text = "气囊位置设置";
            option.AddText("AiebagPosition", "气囊位置", model.AiebagPosition, true);
            UIEditForm frm = new UIEditForm(option);
            frm.ShowDialog();
            if (frm.IsOK)
            {
                model.AiebagPosition = frm["AiebagPosition"].ToString();
                model.IsPhantom = false;

                if (model.ID == 0)
                {
                    if (airbagPositionBLL.Add(model).IsSuccess)
                        UIMessageTip.ShowOk("新增成功");
                    else
                        UIMessageTip.ShowError("新增失败");
                }
                else
                {
                    if (airbagPositionBLL.Update(model).IsSuccess)
                        UIMessageTip.ShowOk("修改成功");
                    else
                        UIMessageTip.ShowError("修改失败");
                }
            }
            frm.Dispose();
        }

        private void EditAirbagConfi(AirbagConfiModel model)
        {
            UIEditOption option = new UIEditOption();
            option.AutoLabelWidth = true;
            option.Text = "气囊配置设置";
            //option.AddText("CarModelCode", "车型代码", model.CarModelCode, true);
            if (model.ID != 0)
                option.AddCombobox("CarModelCode", "车型代码", carModelList, "BarCodeTag", "BarCodeTag", model.CarModelCode);
            else
                option.AddCombobox("CarModelCode", "车型代码", carModelList, "BarCodeTag", "BarCodeTag", "");
            option.AddText("VType", "气囊配置(VIN第7位)", model.VType, true);
            option.AddText("BarCodeEndChar", "气囊标识(最后2位)", model.BarCodeEndChar, true);
            //option.AddText("PositionName", "气囊位置", model.PositionName, true);
            if (model.ID != 0)
                option.AddCombobox("PositionName", "气囊位置", airbagPositionList, "AiebagPosition", "AiebagPosition", model.PositionName);
            else
                option.AddCombobox("PositionName", "气囊位置", airbagPositionList, "AiebagPosition", "AiebagPosition", "");
            option.AddText("BarLength", "气囊长度", model.BarLength.ToString(), true);
            UIEditForm frm = new UIEditForm(option);
            frm.ShowDialog();
            if (frm.IsOK)
            {
                model.CarModelCode = frm["CarModelCode"].ToString();
                model.VType = frm["VType"].ToString();
                model.BarCodeEndChar = frm["BarCodeEndChar"].ToString();
                model.PositionName = frm["PositionName"].ToString();
                model.BarLength = int.Parse(frm["BarLength"].ToString());
                model.IsPhantom = false;

                if (model.ID == 0)
                {
                    if (airbagConfiBLL.Add(model).IsSuccess)
                        UIMessageTip.ShowOk("新增成功");
                    else
                        UIMessageTip.ShowError("新增失败");
                }
                else
                {
                    if (airbagConfiBLL.Update(model).IsSuccess)
                        UIMessageTip.ShowOk("修改成功");
                    else
                        UIMessageTip.ShowError("修改失败");
                }
            }
            frm.Dispose();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission != 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }
            GolbalVariable.WorkShopSet.Position = txtStation.Text;
            GolbalVariable.WorkShopSet.WorkShopNo = int.Parse(txtWorkshopNo.Text);
            GolbalVariable.WorkShopSet.ScanCount = int.Parse(txtScanCount.Text);
            GolbalVariable.WorkShopSet.ComputerNo = txtComputerNo.Text;
            uploadSet.IP = txtIP.Text;
            uploadSet.Port = int.Parse(txtPort.Text);
            uploadSet.UserName = txtUser.Text;
            uploadSet.Password = txtPwd.Text;
            uploadSet.UploadPath = txtUploadPath.Text;
            if (workShopSetBLL.Update(GolbalVariable.WorkShopSet).IsSuccess)
                UIMessageTip.ShowOk("保存成功");
            else
                UIMessageTip.ShowError("保存失败");

            if (uploadSetBLL.Update(uploadSet).IsSuccess)
                UIMessageTip.ShowOk("保存成功");
            else
                UIMessageTip.ShowError("保存失败");
        }

        private void dgvBarCode_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            var model = dgvBarCode.CurrentRow.DataBoundItem as BarCodeConfiModel;
            txtBarName.Text = model.Name;
            txtBarValue.Text = model.Value1.ToString();
        }

        private void dgvCarModel_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            var model = dgvCarModel.CurrentRow.DataBoundItem as CarModelModel;
            txtCarModelCode.Text = model.BarCodeTag;
            txtCarModelEnglisName.Text = model.CarModelCode;
            txtCarModelName.Text = model.CarModelName;
        }

        private void dgvAirbagPosition_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            var model = dgvAirbagPosition.CurrentRow.DataBoundItem as AirbagPositionModel;
            txtPositionName.Text = model.AiebagPosition;
        }

        private void dgvAirbagConfi_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            var model = dgvAirbagConfi.CurrentRow.DataBoundItem as AirbagConfiModel;
            txtAirbagCofig.Text = model.VType;
            cbAirbagCofigCMCode.SelectedValue = model.CarModelCode;
            txtAirbagFlag.Text = model.BarCodeEndChar;
            txtAirbagLength.Text = model.BarLength.ToString();
            cbAirbagPosition.SelectedValue = model.PositionName;
        }

        private void dgvOneToMore_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            var model = dgvOneToMore.CurrentRow.DataBoundItem as AirbagOneToMoreModel;
            cbOneToMoreCarModel.SelectedValue = model.CarModelCode;
            cbOneToMoreVType.SelectedValue = model.VType;
            Thread.Sleep(50);
            cbOneToMoreAirbagGuan.SelectedValue = model.AirbagGuan;
            cbOneToMoreAirbag1.SelectedValue = model.Airbag1;
            cbOneToMoreAirbag2.SelectedValue = model.Airbag2;
            cbOneToMoreAirbag3.SelectedValue = model.Airbag3;
            cbOneToMoreAirbag4.SelectedValue = model.Airbag4;
        }

        private void btnBarUpdate_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission != 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }
            if (dgvBarCode.CurrentRow == null)
            {
                UIMessageBox.ShowError("请先选择要修改的行");
                return;
            }
            txtBarValue.Enabled = true;

            btnBarSave.Enabled = true;
            btnBarCancel.Enabled = true;
            btnBarUpdate.Enabled = false;
        }

        private void btnBarSave_Click(object sender, EventArgs e)
        {
            var model = dgvBarCode.CurrentRow.DataBoundItem as BarCodeConfiModel;
            model.Value1 = int.Parse(txtBarValue.Text);
            if (barCodeConfiBLL.Update(model).IsSuccess)
                UIMessageTip.ShowOk("修改成功");
            else
                UIMessageBox.ShowError("修改失败");
            txtBarValue.Text = "";
            txtBarName.Text = "";
            txtBarValue.Enabled = false;

            btnBarSave.Enabled = false;
            btnBarCancel.Enabled = false;
            btnBarUpdate.Enabled = true;
            LoadDgv();
        }

        private void btnBarCancel_Click(object sender, EventArgs e)
        {
            txtBarValue.Text = "";
            txtBarName.Text = "";
            txtBarValue.Enabled = false;

            btnBarSave.Enabled = false;
            btnBarCancel.Enabled = false;
            btnBarUpdate.Enabled = true;
        }

        private void btnCarModelNew_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission != 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }
            btnFlag = 0;

            txtCarModelCode.Enabled = true;
            txtCarModelEnglisName.Enabled = true;
            txtCarModelName.Enabled = true;

            txtCarModelCode.Text = "";
            txtCarModelEnglisName.Text = "";
            txtCarModelName.Text = "";

            btnCarModelSave.Enabled = true;
            btnCarModelCancel.Enabled = true;
            btnCarModelNew.Enabled = false;
            btnCarModelUpdate.Enabled = false;
            btnCarModelDelete.Enabled = false;
        }

        private void btnCarModelUpdate_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission != 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }
            if (dgvCarModel.CurrentRow == null)
            {
                UIMessageBox.ShowError("请先选择要修改的行");
                return;
            }
            btnFlag = 1;

            txtCarModelCode.Enabled = true;
            txtCarModelEnglisName.Enabled = true;
            txtCarModelName.Enabled = true;

            btnCarModelSave.Enabled = true;
            btnCarModelCancel.Enabled = true;
            btnCarModelNew.Enabled = false;
            btnCarModelUpdate.Enabled = false;
            btnCarModelDelete.Enabled = false;
        }

        private void btnCarModelDelete_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission != 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }
            if (dgvCarModel.CurrentRow == null)
            {
                UIMessageBox.ShowError("请先选择要删除的行");
                return;
            }
            if (!UIMessageDialog.ShowMessageDialog("你确定要删除该车型配置吗？", UILocalize.AskTitle, true, UIStyle.Orange, true, Frame?.TopMost ?? false))
            {
                return;
            }
            var model = dgvCarModel.CurrentRow.DataBoundItem as CarModelModel;
            if (carModelBLL.Delete(model).IsSuccess)
                UIMessageTip.ShowOk("删除成功");
            else
                UIMessageBox.ShowError("删除失败");
            txtCarModelCode.Text = "";
            txtCarModelEnglisName.Text = "";
            txtCarModelName.Text = "";
            btnCarModelUpdate.Enabled = true;
            btnCarModelNew.Enabled = true;
            btnCarModelDelete.Enabled = true;
            btnCarModelSave.Enabled = false;
            btnCarModelCancel.Enabled = false;
            LoadDgv();
        }

        private void btnCarModelSave_Click(object sender, EventArgs e)
        {
            if(btnFlag == 0)
            {
                CarModelModel model = new CarModelModel();
                model.CarModelName = txtCarModelName.Text;
                model.CarModelCode = txtCarModelEnglisName.Text;
                model.BarCodeTag = txtCarModelCode.Text;
                if (carModelBLL.Add(model).IsSuccess)
                    UIMessageTip.ShowOk("新增成功");
                else
                    UIMessageBox.ShowError("新增失败");
            }
            else
            {
                var model = dgvCarModel.CurrentRow.DataBoundItem as CarModelModel;
                model.CarModelName = txtCarModelName.Text;
                model.CarModelCode = txtCarModelEnglisName.Text;
                model.BarCodeTag = txtCarModelCode.Text;
                if (carModelBLL.Update(model).IsSuccess)
                    UIMessageTip.ShowOk("修改成功");
                else
                    UIMessageBox.ShowError("修改失败");
            }
            txtCarModelCode.Text = "";
            txtCarModelEnglisName.Text = "";
            txtCarModelName.Text = "";
            txtCarModelCode.Enabled = false;
            txtCarModelEnglisName.Enabled = false;
            txtCarModelName.Enabled = false;

            btnCarModelUpdate.Enabled = true;
            btnCarModelNew.Enabled = true;
            btnCarModelDelete.Enabled = true;
            btnCarModelSave.Enabled = false;
            btnCarModelCancel.Enabled = false;
            LoadDgv();
        }

        private void btnCarModelCancel_Click(object sender, EventArgs e)
        {
            txtCarModelCode.Text = "";
            txtCarModelEnglisName.Text = "";
            txtCarModelName.Text = "";
            txtCarModelCode.Enabled = false;
            txtCarModelEnglisName.Enabled = false;
            txtCarModelName.Enabled = false;

            btnCarModelUpdate.Enabled = true;
            btnCarModelNew.Enabled = true;
            btnCarModelDelete.Enabled = true;
            btnCarModelSave.Enabled = false;
            btnCarModelCancel.Enabled = false;
        }

        private void btnPositionNew_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission != 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }
            btnFlag = 0;
            txtPositionName.Text = "";
            txtPositionName.Enabled = true;
            btnPositionNew.Enabled = false;
            btnPositionUpdate.Enabled = false;
            btnPositionDelete.Enabled = false;
            btnPositionSave.Enabled = true;
            btnPositionCancel.Enabled = true;
        }

        private void btnPositionUpdate_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission != 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }
            if (dgvAirbagPosition.CurrentRow == null)
            {
                UIMessageBox.ShowError("请先选择要修改的行");
                return;
            }
            btnFlag = 1;
            txtPositionName.Enabled = true;
            btnPositionNew.Enabled = false;
            btnPositionUpdate.Enabled = false;
            btnPositionDelete.Enabled = false;
            btnPositionSave.Enabled = true;
            btnPositionCancel.Enabled = true;
        }

        private void btnPositionDelete_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission != 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }
            if (dgvAirbagPosition.CurrentRow == null)
            {
                UIMessageBox.ShowError("请先选择要删除的行");
                return;
            }
            if (!UIMessageDialog.ShowMessageDialog("你确定要删除该气囊位置吗？", UILocalize.AskTitle, true, UIStyle.Orange, true, Frame?.TopMost ?? false))
            {
                return;
            }
            var model = dgvAirbagPosition.CurrentRow.DataBoundItem as AirbagPositionModel;
            if (airbagPositionBLL.Delete(model).IsSuccess)
                UIMessageTip.ShowOk("删除成功");
            else
                UIMessageBox.ShowError("删除失败");
            txtPositionName.Text = "";
            btnPositionNew.Enabled = true;
            btnPositionUpdate.Enabled = true;
            btnPositionDelete.Enabled = true;
            btnPositionSave.Enabled = false;
            btnPositionCancel.Enabled = false;
            LoadDgv();
        }

        private void btnPositionSave_Click(object sender, EventArgs e)
        {
            if (btnFlag == 0)
            {
                AirbagPositionModel model = new AirbagPositionModel();
                model.AiebagPosition = txtPositionName.Text;
                if (airbagPositionBLL.Add(model).IsSuccess)
                    UIMessageTip.ShowOk("新增成功");
                else
                    UIMessageBox.ShowError("新增失败");
            }
            else
            {
                var model = dgvAirbagPosition.CurrentRow.DataBoundItem as AirbagPositionModel;
                model.AiebagPosition = txtPositionName.Text;
                if (airbagPositionBLL.Update(model).IsSuccess)
                    UIMessageTip.ShowOk("修改成功");
                else
                    UIMessageBox.ShowError("修改失败");
            }
            txtPositionName.Text = "";
            txtPositionName.Enabled = false;

            btnPositionNew.Enabled = true;
            btnPositionUpdate.Enabled = true;
            btnPositionDelete.Enabled = true;
            btnPositionSave.Enabled = false;
            btnPositionCancel.Enabled = false;
            LoadDgv();
        }

        private void btnPositionCancel_Click(object sender, EventArgs e)
        {
            txtPositionName.Text = "";
            txtPositionName.Enabled = false;

            btnPositionNew.Enabled = true;
            btnPositionUpdate.Enabled = true;
            btnPositionDelete.Enabled = true;
            btnPositionSave.Enabled = false;
            btnPositionCancel.Enabled = false;
        }

        private void btnAirbagCofigNew_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission != 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }
            btnFlag = 0;
            txtAirbagCofig.Enabled = true;
            cbAirbagCofigCMCode.Enabled = true;
            txtAirbagFlag.Enabled = true;
            txtAirbagLength.Enabled = true;
            cbAirbagPosition.Enabled = true;

            txtAirbagCofig.Text = "";
            //cbAirbagCofigCMCode.Enabled = true;
            txtAirbagFlag.Text = "";
            txtAirbagLength.Text = "12";
            //cbAirbagPosition.Enabled = true;

            btnAirbagCofigNew.Enabled = false;
            btnAirbagCofigUpdate.Enabled = false;
            btnAirbagCofigDelete.Enabled = false;
            btnAirbagCofigSave.Enabled = true;
            btnAirbagCofigCancel.Enabled = true;
        }

        private void btnAirbagCofigUpdate_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission != 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }
            if (dgvAirbagConfi.CurrentRow == null)
            {
                UIMessageBox.ShowError("请先选择要修改的行");
                return;
            }
            btnFlag = 1;
            txtAirbagCofig.Enabled = true;
            cbAirbagCofigCMCode.Enabled = true;
            txtAirbagFlag.Enabled = true;
            txtAirbagLength.Enabled = true;
            cbAirbagPosition.Enabled = true;

            btnAirbagCofigNew.Enabled = false;
            btnAirbagCofigUpdate.Enabled = false;
            btnAirbagCofigDelete.Enabled = false;
            btnAirbagCofigSave.Enabled = true;
            btnAirbagCofigCancel.Enabled = true;
        }

        private void btnAirbagCofigDelete_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission != 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }
            if (dgvAirbagConfi.CurrentRow == null)
            {
                UIMessageBox.ShowError("请先选择要删除的行");
                return;
            }
            if (!UIMessageDialog.ShowMessageDialog("你确定要删除该气囊位置吗？", UILocalize.AskTitle, true, UIStyle.Orange, true, Frame?.TopMost ?? false))
            {
                return;
            }
            var model = dgvAirbagConfi.CurrentRow.DataBoundItem as AirbagConfiModel;
            if (airbagConfiBLL.Delete(model).IsSuccess)
                UIMessageTip.ShowOk("删除成功");
            else
                UIMessageBox.ShowError("删除失败");
            txtAirbagCofig.Text = "";
            //cbAirbagCofigCMCode.Enabled = true;
            txtAirbagFlag.Text = "";
            txtAirbagLength.Text = "12";
            //cbAirbagPosition.Enabled = true;
            LoadDgv();
        }

        private void btnAirbagCofigSave_Click(object sender, EventArgs e)
        {
            if (btnFlag == 0)
            {
                AirbagConfiModel model = new AirbagConfiModel();
                model.VType = txtAirbagCofig.Text;
                model.CarModelCode = cbAirbagCofigCMCode.SelectedValue.ToString();
                model.BarCodeEndChar = txtAirbagFlag.Text;
                model.BarLength = int.Parse(txtAirbagLength.Text);
                model.PositionName = cbAirbagPosition.SelectedValue.ToString();
                if (airbagConfiBLL.Add(model).IsSuccess)
                    UIMessageTip.ShowOk("新增成功");
                else
                    UIMessageBox.ShowError("新增失败");
            }
            else
            {
                var model = dgvAirbagConfi.CurrentRow.DataBoundItem as AirbagConfiModel;
                model.VType = txtAirbagCofig.Text;
                model.CarModelCode = cbAirbagCofigCMCode.SelectedValue.ToString();
                model.BarCodeEndChar = txtAirbagFlag.Text;
                model.BarLength = int.Parse(txtAirbagLength.Text);
                model.PositionName = cbAirbagPosition.SelectedValue.ToString();
                if (airbagConfiBLL.Update(model).IsSuccess)
                    UIMessageTip.ShowOk("修改成功");
                else
                    UIMessageBox.ShowError("修改失败");
            }
            txtAirbagCofig.Text = "";
            //cbAirbagCofigCMCode.Enabled = true;
            txtAirbagFlag.Text = "";
            txtAirbagLength.Text = "12";
            //cbAirbagPosition.Enabled = true;
            txtAirbagCofig.Enabled = false;
            cbAirbagCofigCMCode.Enabled = false;
            txtAirbagFlag.Enabled = false;
            txtAirbagLength.Enabled = false;
            cbAirbagPosition.Enabled = false;

            btnAirbagCofigNew.Enabled = true;
            btnAirbagCofigUpdate.Enabled = true;
            btnAirbagCofigDelete.Enabled = true;
            btnAirbagCofigSave.Enabled = false;
            btnAirbagCofigCancel.Enabled = false;
            LoadDgv();
        }

        private void btnAirbagCofigCancel_Click(object sender, EventArgs e)
        {
            txtAirbagCofig.Text = "";
            //cbAirbagCofigCMCode.Enabled = true;
            txtAirbagFlag.Text = "";
            txtAirbagLength.Text = "12";
            //cbAirbagPosition.Enabled = true;
            txtAirbagCofig.Enabled = false;
            cbAirbagCofigCMCode.Enabled = false;
            txtAirbagFlag.Enabled = false;
            txtAirbagLength.Enabled = false;
            cbAirbagPosition.Enabled = false;

            btnAirbagCofigNew.Enabled = true;
            btnAirbagCofigUpdate.Enabled = true;
            btnAirbagCofigDelete.Enabled = true;
            btnAirbagCofigSave.Enabled = false;
            btnAirbagCofigCancel.Enabled = false;
        }

        //string[] 数组1 = systemDeviceList.Select(x => x.device_name).ToArray();

        private void btnOneToMoreNew_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission != 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }
            btnFlag = 0;
            cbOneToMoreCarModel.Enabled = true;
            cbOneToMoreVType.Enabled = true;
            cbOneToMoreAirbagGuan.Enabled = false;
            cbOneToMoreAirbag1.Enabled = false;
            cbOneToMoreAirbag2.Enabled = false;
            cbOneToMoreAirbag3.Enabled = false;
            cbOneToMoreAirbag4.Enabled = false;

            cbOneToMoreCarModel.SelectedIndex = -1;
            cbOneToMoreVType.SelectedIndex = -1;
            cbOneToMoreAirbagGuan.DataSource = null;
            cbOneToMoreAirbag1.DataSource = null;
            cbOneToMoreAirbag2.DataSource = null;
            cbOneToMoreAirbag3.DataSource = null;
            cbOneToMoreAirbag4.DataSource = null;

            btnOneToMoreNew.Enabled = false;
            btnOneToMoreUpdate.Enabled = false;
            btnOneToMoreDelete.Enabled = false;
            btnOneToMoreSave.Enabled = true;
            btnOneToMoreCancel.Enabled = true;
        }

        private void btnOneToMoreUpdate_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission != 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }
            if (dgvOneToMore.CurrentRow == null)
            {
                UIMessageBox.ShowError("请先选择要修改的行");
                return;
            }

            btnFlag = 1;
            cbOneToMoreCarModel.Enabled = false;
            cbOneToMoreVType.Enabled = false;
            cbOneToMoreAirbagGuan.Enabled = true;
            cbOneToMoreAirbag1.Enabled = true;
            cbOneToMoreAirbag2.Enabled = true;
            cbOneToMoreAirbag3.Enabled = true;
            cbOneToMoreAirbag4.Enabled = true;

            btnOneToMoreNew.Enabled = false;
            btnOneToMoreUpdate.Enabled = false;
            btnOneToMoreDelete.Enabled = false;
            btnOneToMoreSave.Enabled = true;
            btnOneToMoreCancel.Enabled = true;
        }

        private void btnOneToMoreDelete_Click(object sender, EventArgs e)
        {
            if (ApplicationCache.CurrentUser.Permission != 0)
            {
                UIMessageBox.Show("该操作需要管理员权限，请先切换管理员账号！");
                return;
            }
            if (dgvOneToMore.CurrentRow == null)
            {
                UIMessageBox.ShowError("请先选择要删除的行");
                return;
            }
            if (!UIMessageDialog.ShowMessageDialog("你确定要删除该气囊一对多设置吗？", UILocalize.AskTitle, true, UIStyle.Orange, true, Frame?.TopMost ?? false))
            {
                return;
            }
            var model = dgvOneToMore.CurrentRow.DataBoundItem as AirbagOneToMoreModel;
            if (airbagOneToMoreBLL.Delete(model).IsSuccess)
                UIMessageTip.ShowOk("删除成功");
            else
                UIMessageBox.ShowError("删除失败");
            cbOneToMoreCarModel.SelectedIndex = -1;
            cbOneToMoreVType.SelectedIndex = -1;
            cbOneToMoreAirbagGuan.SelectedIndex = -1;
            cbOneToMoreAirbag1.SelectedIndex = -1;
            cbOneToMoreAirbag2.SelectedIndex = -1;
            cbOneToMoreAirbag3.SelectedIndex = -1;
            cbOneToMoreAirbag4.SelectedIndex = -1;
            LoadDgv();
        }

        private void btnOneToMoreSave_Click(object sender, EventArgs e)
        {
            if (cbOneToMoreAirbagGuan.SelectedValue == null)
            {
                UIMessageBox.ShowError("请选择车型和气囊配置！");
                return;
            }
                if (cbOneToMoreAirbagGuan.SelectedValue.ToString() == "--无--")
            {
                UIMessageBox.ShowError("必须选择气囊总称！");
                return;
            }
            //计算选择的分气囊个数，小于2个时提示错误
            int airbagCount = 0;
            if (cbOneToMoreAirbag1.SelectedValue.ToString() != "--无--")
                airbagCount++;
            if (cbOneToMoreAirbag2.SelectedValue.ToString() != "--无--")
                airbagCount++;
            if (cbOneToMoreAirbag3.SelectedValue.ToString() != "--无--")
                airbagCount++;
            if (cbOneToMoreAirbag4.SelectedValue.ToString() != "--无--")
                airbagCount++;
            if(airbagCount<2)
            {
                UIMessageBox.ShowError("分气囊不能少于两个！");
                return;
            }
            if (btnFlag == 0)
            {
                AirbagOneToMoreModel model = new AirbagOneToMoreModel();
                model.VType = cbOneToMoreVType.SelectedValue.ToString();
                model.CarModelCode = cbOneToMoreCarModel.SelectedValue.ToString();
                model.AirbagGuan = cbOneToMoreAirbagGuan.SelectedValue.ToString() == "--无--"?"": cbOneToMoreAirbagGuan.SelectedValue.ToString();
                model.Airbag1 = cbOneToMoreAirbag1.SelectedValue.ToString() == "--无--"? "" : cbOneToMoreAirbag1.SelectedValue.ToString();
                model.Airbag2 = cbOneToMoreAirbag2.SelectedValue.ToString() == "--无--"? "" : cbOneToMoreAirbag2.SelectedValue.ToString();
                model.Airbag3 = cbOneToMoreAirbag3.SelectedValue.ToString() == "--无--"? "" : cbOneToMoreAirbag3.SelectedValue.ToString();
                model.Airbag4 = cbOneToMoreAirbag4.SelectedValue.ToString() == "--无--" ? "" : cbOneToMoreAirbag4.SelectedValue.ToString();
                if (airbagOneToMoreBLL.Add(model).IsSuccess)
                    UIMessageTip.ShowOk("新增成功");
                else
                    UIMessageBox.ShowError("新增失败");
            }
            else
            {
                var model = dgvOneToMore.CurrentRow.DataBoundItem as AirbagOneToMoreModel;
                model.VType = cbOneToMoreVType.SelectedValue.ToString();
                model.CarModelCode = cbOneToMoreCarModel.SelectedValue.ToString();
                model.AirbagGuan = cbOneToMoreAirbagGuan.SelectedValue.ToString() == "--无--" ? "" : cbOneToMoreAirbagGuan.SelectedValue.ToString();
                model.Airbag1 = cbOneToMoreAirbag1.SelectedValue.ToString() == "--无--" ? "" : cbOneToMoreAirbag1.SelectedValue.ToString();
                model.Airbag2 = cbOneToMoreAirbag2.SelectedValue.ToString() == "--无--" ? "" : cbOneToMoreAirbag2.SelectedValue.ToString();
                model.Airbag3 = cbOneToMoreAirbag3.SelectedValue.ToString() == "--无--" ? "" : cbOneToMoreAirbag3.SelectedValue.ToString();
                model.Airbag4 = cbOneToMoreAirbag4.SelectedValue.ToString() == "--无--" ? "" : cbOneToMoreAirbag4.SelectedValue.ToString();
                if (airbagOneToMoreBLL.Update(model).IsSuccess)
                    UIMessageTip.ShowOk("修改成功");
                else
                    UIMessageBox.ShowError("修改失败");
            }
            btnOneToMoreNew.Enabled = true;
            btnOneToMoreUpdate.Enabled = true;
            btnOneToMoreDelete.Enabled = true;
            btnOneToMoreSave.Enabled = false;
            btnOneToMoreCancel.Enabled = false;

            cbOneToMoreCarModel.Enabled = false;
            cbOneToMoreVType.Enabled = false;
            cbOneToMoreAirbagGuan.Enabled = false;
            cbOneToMoreAirbag1.Enabled = false;
            cbOneToMoreAirbag2.Enabled = false;
            cbOneToMoreAirbag3.Enabled = false;
            cbOneToMoreAirbag4.Enabled = false;

            cbOneToMoreCarModel.SelectedIndex = -1;
            cbOneToMoreVType.SelectedIndex = -1;
            Thread.Sleep(50);
            cbOneToMoreAirbagGuan.SelectedIndex = -1;
            cbOneToMoreAirbag1.SelectedIndex = -1;
            cbOneToMoreAirbag2.SelectedIndex = -1;
            cbOneToMoreAirbag3.SelectedIndex = -1;
            cbOneToMoreAirbag4.SelectedIndex = -1;

            LoadDgv();
        }

        private void btnOneToMoreCancel_Click(object sender, EventArgs e)
        {
            cbOneToMoreCarModel.Enabled = false;
            cbOneToMoreVType.Enabled = false;
            cbOneToMoreAirbagGuan.Enabled = false;
            cbOneToMoreAirbag1.Enabled = false;
            cbOneToMoreAirbag2.Enabled = false;
            cbOneToMoreAirbag3.Enabled = false;
            cbOneToMoreAirbag4.Enabled = false;

            btnOneToMoreNew.Enabled = true;
            btnOneToMoreUpdate.Enabled = true;
            btnOneToMoreDelete.Enabled = true;
            btnOneToMoreSave.Enabled = false;
            btnOneToMoreCancel.Enabled = false;

            cbOneToMoreVType.SelectedIndex = -1;
            cbOneToMoreCarModel.SelectedIndex = -1;
            Thread.Sleep(50);
            cbOneToMoreAirbagGuan.SelectedIndex = -1;
            cbOneToMoreAirbag1.SelectedIndex = -1;
            cbOneToMoreAirbag2.SelectedIndex = -1;
            cbOneToMoreAirbag3.SelectedIndex = -1;
            cbOneToMoreAirbag4.SelectedIndex = -1;
        }

        private void cbOneToMoreCarModel_SelectedValueChanged(object sender, EventArgs e)
        {
            if (cbOneToMoreCarModel.SelectedValue == null|| cbOneToMoreVType.SelectedValue == null)
                return;
            var dataSourceList = airbagConfiList.Where(t => t.CarModelCode == cbOneToMoreCarModel.SelectedValue.ToString() && t.VType == cbOneToMoreVType.SelectedValue.ToString()).ToList();
            dataSourceList.Insert(0, new AirbagConfiModel { PositionName = "--无--" });
            cbOneToMoreAirbagGuan.DataSource = dataSourceList;
            cbOneToMoreAirbagGuan.DisplayMember = "PositionName";
            cbOneToMoreAirbagGuan.ValueMember = "PositionName";
            cbOneToMoreAirbag1.DataSource = dataSourceList;
            cbOneToMoreAirbag1.DisplayMember = "PositionName";
            cbOneToMoreAirbag1.ValueMember = "PositionName";
            cbOneToMoreAirbag2.DataSource = dataSourceList;
            cbOneToMoreAirbag2.DisplayMember = "PositionName";
            cbOneToMoreAirbag2.ValueMember = "PositionName";
            cbOneToMoreAirbag3.DataSource = dataSourceList;
            cbOneToMoreAirbag3.DisplayMember = "PositionName";
            cbOneToMoreAirbag3.ValueMember = "PositionName";
            cbOneToMoreAirbag4.DataSource = dataSourceList;
            cbOneToMoreAirbag4.DisplayMember = "PositionName";
            cbOneToMoreAirbag4.ValueMember = "PositionName";

            if(btnOneToMoreNew.Enabled == false || btnOneToMoreUpdate.Enabled == false)
            {
                cbOneToMoreAirbagGuan.Enabled = true;
                cbOneToMoreAirbag1.Enabled = true;
                cbOneToMoreAirbag2.Enabled = true;
                cbOneToMoreAirbag3.Enabled = true;
                cbOneToMoreAirbag4.Enabled = true;
            }
        }

        private void cbOneToMoreVType_SelectedValueChanged(object sender, EventArgs e)
        {
            if (cbOneToMoreCarModel.SelectedValue == null || cbOneToMoreVType.SelectedValue == null)
                return;
            var dataSourceList = airbagConfiList.Where(t => t.CarModelCode == cbOneToMoreCarModel.SelectedValue.ToString() && t.VType == cbOneToMoreVType.SelectedValue.ToString()).ToList();
            dataSourceList.Insert(0, new AirbagConfiModel { PositionName = "--无--" });
            cbOneToMoreAirbagGuan.DataSource = dataSourceList;
            cbOneToMoreAirbagGuan.DisplayMember = "PositionName";
            cbOneToMoreAirbagGuan.ValueMember = "PositionName";
            cbOneToMoreAirbag1.DataSource = dataSourceList;
            cbOneToMoreAirbag1.DisplayMember = "PositionName";
            cbOneToMoreAirbag1.ValueMember = "PositionName";
            cbOneToMoreAirbag2.DataSource = dataSourceList;
            cbOneToMoreAirbag2.DisplayMember = "PositionName";
            cbOneToMoreAirbag2.ValueMember = "PositionName";
            cbOneToMoreAirbag3.DataSource = dataSourceList;
            cbOneToMoreAirbag3.DisplayMember = "PositionName";
            cbOneToMoreAirbag3.ValueMember = "PositionName";
            cbOneToMoreAirbag4.DataSource = dataSourceList;
            cbOneToMoreAirbag4.DisplayMember = "PositionName";
            cbOneToMoreAirbag4.ValueMember = "PositionName";

            if (btnOneToMoreNew.Enabled == false || btnOneToMoreUpdate.Enabled == false)
            {
                cbOneToMoreAirbagGuan.Enabled = true;
                cbOneToMoreAirbag1.Enabled = true;
                cbOneToMoreAirbag2.Enabled = true;
                cbOneToMoreAirbag3.Enabled = true;
                cbOneToMoreAirbag4.Enabled = true;
            }
        }
    }
}
